package gamesys.games.particlesystem
{
	import gamesys.games.particlesystem.particleloader.ParticleLoader;
	import gamesys.games.particlesystem.particleloader.ParticleLoaderEvent;

	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.utils.getTimer;

	/**
	 * @author robertthurston
	 */
	public class AbstractTest extends Sprite
	{
		protected var _debugTextField : TextField;
		private var _lastTime : int;

		public function AbstractTest()
		{
			var particleLoader : ParticleLoader = new ParticleLoader();
			particleLoader.addEventListener(ParticleLoaderEvent.COMPLETE, onParticlesLoaded);
			particleLoader.loadAssets(["../assets/Particles.swf"]);
		}

		private function onParticlesLoaded(event : ParticleLoaderEvent) : void
		{
			init();
			createDebugger();
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
			stage.addEventListener(MouseEvent.CLICK, onClick);
		}

		private function createDebugger() : void
		{
			_debugTextField = new TextField();
			_debugTextField.backgroundColor = 0xFFFFFF;
			_debugTextField.background = true;
			_debugTextField.autoSize = TextFieldAutoSize.LEFT;

			addChild(_debugTextField);
		}

		protected function onClick(event : MouseEvent) : void
		{
		}

		protected function onEnterFrame(event : Event) : void
		{
		}

		public function updateDebugger(totalParticles : uint) : void
		{
			var currentTime : Number = getTimer();
			var frameRate : uint = 1000 / (currentTime - _lastTime);

			_debugTextField.text = "FrameRate:" + frameRate + "/" + stage.frameRate + "\n";
			_debugTextField.text += "TotalParticles:" + totalParticles;

			_lastTime = currentTime;
		}

		protected function init() : void
		{
		}
	}
}
